package com.softer.wxzj.controller;

import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.aop.annotation.LogRecord;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.entity.DongleInfo;
import com.softer.wxzj.entity.SysCorpOperator;
import com.softer.wxzj.service.DongleInfoService;
import com.softer.wxzj.service.SysCorpOperatorService;
import com.softer.wxzj.service.SysOperatorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description: 企业用户信息
 * @ClassName: SysCorpOperatorController
 * @author: ludexing
 * @date: 2019-05-10
 */
@RestController
@RequestMapping("/sysCorpOperator")
@Slf4j
public class SysCorpOperatorController {

    @Autowired
    private SysCorpOperatorService sysCorpOperatorService;
    @Autowired
    private SysOperatorService sysOperatorService;
    @Autowired
    private DongleInfoService dongleInfoService;

    /**
     * 主管端添加
     *
     * @param sysCorpOperator
     * @return
     */
    @RequestMapping("/add")
    @LogRecord(description = "主管端添加企业信息", operationUnit = LogOperationUnit.SYS_CORP_OPERATOR, operationType = LogOperationType.INSERT)
    public CommonResult add(SysCorpOperator sysCorpOperator) {
        return sysCorpOperatorService.insert(sysCorpOperator);
    }

    /**
     * state 0 停用 1启用
     * @param state
     * @return
     */
    @LogRecord(description = "修改企业用户的 状态", operationUnit = LogOperationUnit.SYS_CORP_OPERATOR, operationType = LogOperationType.UPDATE)
    @RequestMapping("/enable")
    public CommonResult enable(String state) {
        SysCorpOperator info = new SysCorpOperator();
        info.setState(state);
        return sysCorpOperatorService.update(info);
    }

    /**
     * 重置密码为123456
     * @param id
     * @return
     */
    @LogRecord(description = "重置企业用户的密码", operationUnit = LogOperationUnit.SYS_CORP_OPERATOR, operationType = LogOperationType.UPDATE)
    @RequestMapping("/resetPassword")
    public CommonResult resetPassword(String id) {
        return sysOperatorService.resetCorpPassword(id);
    }


    @LogRecord(description = "查看用户绑定的加密狗", operationUnit = LogOperationUnit.SYS_CORP_OPERATOR, operationType = LogOperationType.SELECT)
    @RequestMapping("/findDongleInfoList")
    public List<DongleInfo> findDongleInfoList(String id) {
        DongleInfo info = new DongleInfo();
        info.setOperType("2");
        info.setOperId(id);
        return dongleInfoService.findDongleInfoList(info);
    }

    /**
     * 获取企业信息列表
     *
     * @param page            分页
     * @param sysCorpOperator 企业信息参数
     * @return 企业信息列表
     */
    @RequestMapping("/findList")
    @LogRecord(description = "获取企业信息列表", operationUnit = LogOperationUnit.SYS_CORP_OPERATOR, operationType = LogOperationType.SELECT)
    public PageInfo<SysCorpOperator> findList(Page page, SysCorpOperator sysCorpOperator, String fuzzy) {
        return sysCorpOperatorService.findList(page, sysCorpOperator, fuzzy);
    }

    /**
     * 根据id获取企业详情
     *
     * @param id 企业id
     * @return 企业基本信息
     */
    @RequestMapping("/getInfo")
    @LogRecord(description = "根据id获取企业基本信息详情", operationUnit = LogOperationUnit.SYS_CORP_OPERATOR, operationType = LogOperationType.SELECT)
    public SysCorpOperator getInfo(String id) {
        return sysCorpOperatorService.getInfo(id);
    }


}
